<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="查询" prop="companyName">
        <el-input v-model="queryParams.companyName" placeholder="请输入公司名称/零活名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!-- <el-form-item label="工作地址" prop="companyAddress">
        <el-input v-model="queryParams.companyAddress" placeholder="请输入工作地址" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item> -->



      <el-form-item label="审核状态" prop="approved ">
        <!-- <el-input v-model="queryParams.params.approved " placeholder="请选择审核状态" clearable @keyup.enter.native="handleQuery" /> -->
        <el-select v-model="queryParams.approved" placeholder="请选择审核状态" clearable>
          <el-option v-for="dict in dict.type.approve_status" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>

      <el-form-item label="薪酬" prop="salary">
        <el-input v-model="queryParams.params.salary" placeholder="请输入薪酬" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item label="结算方式" prop="settlementMethodCode">
        <el-select v-model="queryParams.settlementMethodCode" placeholder="请选择结算方式" clearable>
          <el-option v-for="dict in dict.type.settlement_method" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>

      <el-form-item label="年龄" prop="limitAge">
        <el-input v-model="queryParams.params.limitAge" placeholder="请输入年龄" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item prop="beginTime" label="招聘日期">
        <el-date-picker v-model="dateRange" type="daterange" style="width: 215px" value-format="yyyy-MM-dd"
          range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['jobs:info:add']">新增</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['jobs:info:edit']">修改</el-button>
      </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['jobs:info:remove']">删除</el-button>
      </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['jobs:info:export']" v-show="false">导出</el-button>
      </el-col> -->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="infoList" @selection-change="handleSelectionChange">
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <el-table-column label="编号" align="center" prop="id" />
      <!-- <el-table-column label="零活名称" align="center" prop="gigJobName" /> -->
      <el-table-column label="公司名称" align="center" prop="companyName" />
      <el-table-column label="招工人员" align="center" prop="companyId">
        <template slot-scope="scope">
          {{ getCompanyLabel(scope.row.companyId ? scope.row.companyId : 0) }}
        </template>
      </el-table-column>
      <!-- <el-table-column label="公司地址" align="center" prop="companyAddress" style="overflow-x: hidden;text-overflow: ellipsis;
  white-space: nowrap;" /> -->
      <el-table-column label="零工类型" align="center" prop="gigCode">
        <template slot-scope="scope">
          <span v-for="(item, index) in scope.row.typeArr" :key="index">
            {{ item.typeName }}-{{ item.gigName }}<br />
          </span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="岗位要求" align="center" prop="jobRequirement">
        <template slot-scope="scope">
          <el-popover placement="top-start" width="200" trigger="hover" :content="scope.row.jobRequirement">
            <el-button slot="reference" type="text">
              {{ scope.row.jobRequirement }}</el-button>
          </el-popover>
        </template>
      </el-table-column> -->
      <el-table-column label="薪资范围" align="center">
        <template slot-scope="scope">
          {{ getSalaryRange(scope.row) }}元/天
        </template>
      </el-table-column>

      <el-table-column label="招工人数" align="center" prop="needCount" />
      <el-table-column label="结算方式" align="center" prop="settlementMethodCode">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.settlement_method" :value="scope.row.settlementMethodCode" />
        </template>
      </el-table-column>
      <el-table-column label="招聘日期" align="center" prop="beginTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.beginTime, "{y}-{m}-{d}") }}</span> -
          <span>{{ parseTime(scope.row.endTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>

      <el-table-column label="审核状态" align="center" prop="approved">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.approve_status" :value="scope.row.approved" />
        </template>
      </el-table-column>

      <el-table-column label="年龄范围" align="center" prop="limitAgeMin">
        <template slot-scope="scope">
          {{ scope.row.limitAgeMin }}-{{ scope.row.limitAgeMax }}
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center" width="240px" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-search" @click="handledView(scope.row)"
            v-hasPermi="['jobs:info:edit']">查看</el-button>
          <el-button v-if="scope.row.showStatus === 0" size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['jobs:info:edit']">修改</el-button>
          <el-button v-if="scope.row.showStatus === 5 || scope.row.showStatus === 0" size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['jobs:info:remove']">删除</el-button>
          <el-dropdown @command="(command) => handleCommand(command, scope.row)" v-if="scope.row.showStatus === 1" >
            <span class="el-dropdown-link" >
              <el-button size="mini" type="text" icon="el-icon-coin" v-hasPermi="[
                'jobs:info:approved',
                'jobs:info:disApproved',
                'jobs:info:unApproved',
              ]">审核</el-button>
              <i class="el-icon-arrow-down el-icon--right"></i>
            </span>
            <el-dropdown-menu slot="dropdown" key="0">
              <el-dropdown-item command="pass" key="1">
                <el-button size="mini" type="text" v-hasPermi="['jobs:info:approved']">通过</el-button>
              </el-dropdown-item>
              <el-dropdown-item command="reject" key="2">
                <el-button size="mini" type="text" v-hasPermi="['jobs:info:disApproved']">不通过</el-button>
              </el-dropdown-item>
              <el-dropdown-item command="reset" key="3">
                <el-button size="mini" type="text" v-hasPermi="['jobs:info:unApproved']">重置</el-button>
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改零工岗位对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="700px" append-to-body ref="dialog">
      <el-form ref="form" :model="form" :rules="rules" :inline="true" label-width="80px">
        <el-form-item label="零活名称" prop="gigJobName">
          <el-input v-model="form.gigJobName" placeholder="请输入零活名称" />
        </el-form-item>

        <el-form-item label="公司名称" prop="companyName">
          <el-input v-model="form.companyName" placeholder="请输入公司名称没有填个人" />
        </el-form-item>

        <el-form-item label="招工人员" prop="companyId">
          <el-select v-model="form.companyId" placeholder="请选择" style="width: 200px">
            <el-option v-for="item in userOptions" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="招工人数" prop="needCount">
          <el-input v-model="form.needCount" placeholder="请输入招工人数,默认为1" style="width: 200px" />
        </el-form-item>

        <el-form-item label="工作地址" prop="address">
          <el-cascader
            v-model="form.address"
            placeholder="选择工作地区"
            :options="addressOptions"
            :props="{ label: 'name', value: 'id' }"
            style="width: 200px"
            @change="(value)=>addressChange(value)"
            filterable></el-cascader>
        </el-form-item>

        <el-form-item label="详细地址" prop="companyAddress">
          <el-input v-model="form.companyAddress" placeholder="请输入详细地址" />
        </el-form-item>

        <el-form-item label="零工行业" prop="industry">
          <el-select v-model="form.industry" placeholder="请选择行业" style="width: 200px" @change="workChange">
            <el-option v-for="item in workOptions" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="零工类型" prop="gigCodeArr">
          <el-select v-model="form.gigCodeArr" multiple placeholder="请选择行业" style="width: 200px">
            <el-option v-for="item in workTypeOptions" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>

        <!-- <el-form-item label="地址经度" prop="mapLongitude">
            <el-input v-model="form.mapLongitude" placeholder="请输入地址经度" />
          </el-form-item>
          <el-form-item label="地址纬度" prop="mapLatitude">
            <el-input v-model="form.mapLatitude" placeholder="请输入地址纬度" />
          </el-form-item> -->

        <!-- <el-form-item label="薪酬下限" prop="salaryMin">
            <el-input v-model="form.salaryMin" placeholder="请输入薪酬下限" />
          </el-form-item>
          <el-form-item label="薪酬上限" prop="salaryMax">
            <el-input v-model="form.salaryMax" placeholder="请输入薪酬上限" />
          </el-form-item> -->

        <el-form-item label="薪酬范围" prop="salary">
          <el-input v-model="form.salary" placeholder="请输入薪资范围" style="width: 200px" >
            <template slot="append">元/天</template>
          </el-input>
        </el-form-item>

        <!-- <el-form-item label="面议" prop="negotiable">
            <el-input v-model="form.negotiable" placeholder="请输入面议" />
          </el-form-item> -->
        
        <!-- <el-form-item label="不限人数" prop="unLimitCount">
            <el-input v-model="form.unLimitCount" placeholder="请输入不限人数" />
          </el-form-item> -->
        <!-- <el-form-item label="申请人数" prop="applyCount">
            <el-input v-model="form.applyCount" placeholder="请输入申请人数" />
          </el-form-item> -->
        <el-form-item label="结算方式" prop="settlementMethodCode">
          <el-select v-model="form.settlementMethodCode" placeholder="请选择结算方式" style="width: 200px">
            <el-option v-for="dict in dict.type.settlement_method" :key="dict.value" :label="dict.label"
              :value="dict.value"></el-option>
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="开始时间" prop="beginTime">
            <el-date-picker clearable style="width: 200px;" v-model="form.beginTime" type="datetime" value-format="yyyy-MM-dd HH:mm:ss"
              placeholder="请选择招聘开始时间">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="结束时间" prop="endTime">
            <el-date-picker clearable style="width: 200px;" v-model="form.endTime" type="datetime" value-format="yyyy-MM-dd HH:mm:ss"
              placeholder="请选择招聘结束时间">
            </el-date-picker>
          </el-form-item> -->

        <!-- <el-form-item label="年龄下限" prop="limitAgeMin">
            <el-input v-model="form.limitAgeMin" placeholder="请输入年龄下限" />
          </el-form-item>
          <el-form-item label="年龄上限" prop="limitAgeMax">
            <el-input v-model="form.limitAgeMax" placeholder="请输入年龄上限" />
          </el-form-item> -->
        <el-form-item label="年龄范围" prop="age">
          <el-input v-model="form.age" placeholder="请输入年龄范围,例18-55" style="width: 200px"></el-input>
        </el-form-item>

        <el-form-item label="招聘时间" prop="time">
          <el-date-picker v-model="form.time" type="datetimerange" value-format="yyyy-MM-dd HH:mm:ss"
            range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" style="width: 370px" @change="onTimeChange">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="岗位要求" prop="jobRequirement">
          <el-input type="textarea" v-model="form.jobRequirement" placeholder="请输入岗位要求" style="width: 370px" />
        </el-form-item>

        <el-form-item label="状态" prop="approved" v-show="false">
          <el-radio-group v-model="form.approved">
            <el-radio v-for="dict in dict.type.approve_status" :key="dict.value" :label="dict.value">{{ dict.label
              }}</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 岗位详情 -->
    <el-drawer style="padding-top: 80px" title="详情" :modal="false" :visible.sync="drawer" direction="rtl"
      :before-close="handleClose">
      <el-descriptions title="" style="padding: 0 40px" :column="1">
        <el-descriptions-item label="零工名称">{{
          this.details.gigJobName
          }}</el-descriptions-item>
        <el-descriptions-item label="公司名称">{{
          this.details.companyName
          }}</el-descriptions-item>
        <el-descriptions-item label="招工人员">{{
          getCompanyLabel(this.details.companyId)
          }}</el-descriptions-item>
        <el-descriptions-item label="工作地区">{{
          this.details.addressName
          }}</el-descriptions-item>
        <el-descriptions-item label="详细地址">{{
          this.details.companyAddress
          }}</el-descriptions-item>
        <el-descriptions-item label="零工行业">
          {{ this.details.industry }}
        </el-descriptions-item>
        <el-descriptions-item label="薪资范围">{{ getSalaryRange(this.details) }}元/天</el-descriptions-item>
        <el-descriptions-item label="招工人数">{{
          this.details.needCount
          }}</el-descriptions-item>
        <el-descriptions-item label="结算方式">
          <dict-tag :options="dict.type.settlement_method" :value="this.details.settlementMethodCode" />
        </el-descriptions-item>
        <el-descriptions-item label="时间范围">
          <span>{{ parseTime(this.details.beginTime, "{y}-{m}-{d}") }}</span> ~
          <span>{{ parseTime(this.details.endTime, "{y}-{m}-{d}") }}</span>
        </el-descriptions-item>
        <el-descriptions-item label="年龄范围">
          {{ this.details.limitAgeMin }}-{{ this.details.limitAgeMax }}
        </el-descriptions-item>
        <el-descriptions-item label="审核状态">
          <dict-tag :options="dict.type.approve_status" :value="this.details.approved" />
        </el-descriptions-item>
        <el-descriptions-item label="岗位要求">{{
          this.details.jobRequirement
          }}</el-descriptions-item>
      </el-descriptions>
    </el-drawer>
  </div>
</template>

<script>
import {
  addInfo,
  checkApproved,
  checkDisApproved,
  checkUnApproved,
  delInfo,
  getInfo,
  listInfo,
  updateInfo,
} from "@/api/jobs/info";
import { typeCascadeList } from "@/api/market/type";
import { findRegionTreeLevel3 } from "@/api/system/region";
import { userOptions } from "@/api/user/info";
import { getRegionNameById } from "@/utils/user";
export default {
  name: "Info",
  dicts: ["settlement_method", "sys_normal_disable", "approve_status"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 零工岗位表格数据
      infoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 用户options
      userOptions: [],
      // 详情
      drawer: false,
      // 查询参数
      dateRange: [], // 时间
      // 时间
      time: "",
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        companyName: null,
        companyAddress: null,
        gigCode: null,
        salaryMin: null,
        salaryMax: null,
        needCount: 1,
        settlementMethodCode: null,
        beginTime: null,
        endTime: null,
        limitAgeMin: null,
        limitAgeMax: null,
        params: {
          salary: "", // 薪资
          limitAge: null, // 年龄
        },
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        gigJobName: [
          {
            required: true,
            message: "请填写零活名称",
            trigger: "blur",
          },
        ],
        companyName: [
          {
            required: true,
            message: "请填写公司名称，没有填个人",
            trigger: "blur",
          },
        ],
        companyId: [
          {
            required: true,
            message: "请选择招工人员",
            trigger: "blur",
          },
        ],
        industry: [
          {
            required: true,
            message: "请选择行业",
            trigger: "blur",
          },
        ],
        gigCodeArr: [
          {
            required: true,
            message: "请选择类型",
            trigger: "blur",
          },
        ],
        salary: [
          {
            required: true,
            message: "请输入薪资范围",
            trigger: "blur",
          },
          { validator: this.validateSalaryRange, trigger: "blur" },
        ],
        time: [
          {
            required: true,
            message: "请选择招聘时间",
            trigger: "blur",
          },
        ],
        settlementMethodCode: [
          {
            required: true,
            message: "请选择结算方式",
            trigger: "blur",
          },
        ],
        companyAddress: [
          {
            required: true,
            message: "请输入工作地址",
            trigger: "blur",
          },
        ],
        jobRequirement: [
          {
            required: true,
            message: "请输入岗位要求",
            trigger: "blur",
          },
        ],
        address: [
          {
            required: true,
            message: "请选择地区",
            trigger: "blur",
          },
        ],
        age: [
          {
            required: true,
            message: "年龄范围不能为空,例如18-55",
            trigger: "blur",
          },
          {
            validator: (rule, value, callback) => {
              const agePattern = /^(\d{1,3})-(\d{1,3})$/;
              if (!agePattern.test(value)) {
                callback(new Error("请输入正确的年龄范围格式，例如18-55"));
              } else {
                const [minAge, maxAge] = value.split("-").map(Number);
                if (minAge < 18 || maxAge > 90 || minAge > maxAge) {
                  callback(
                    new Error("年龄范围应为18-90岁，且最小值不能大于最大值")
                  );
                } else {
                  callback();
                }
              }
            },
            trigger: "blur",
          },
        ],
      },
      // 岗位 可多选
      selectedWorkValue: [],
      // 行业 数据
      selectedWork: "",
      // 岗位 数据
      workOptions: [],
      // 类型数据
      workTypeOptions: [],
      selectedWorkTypeValue: [],
      // 查看
      details: {},
      addressOptions: [],
    };
  },
  created() {
    this.getUserOptions();
    this.getTypeCascadeOptions();
    this.getAddressOption();
    this.getList();
  },
  methods: {
    //
    handleClose() {
      this.drawer = false;
    },
    // 时间
    onTimeChange(value) {
      console.log("时间", value);
    },

    // 地区
    addressChange(value){
      console.log('地区',value);
      this.form.regionProvince = value[0];
			this.form.regionCity = value[1];
			this.form.regionDistrict = value[2];
    },

    // 获取地区数据
    getAddressOption(){
      findRegionTreeLevel3().then((response)=>{
        this.addressOptions = response.data
        console.log('获取地区数据',response.data,this.addressOptions);
      })
    },
    //
    handledView(row) {
      this.reset();
      const id = row.id || this.ids;
      console.log("修改按钮操作", row);
      getInfo(id).then((response) => {
        const industry = this.findParentValue(
          this.workOptions,
          response.data.gigCode
        );
        if(industry){
          this.workChange(industry);
        }
        const address = {
						regionProvinceId: response.data.regionProvince,
						regionCityId: response.data.regionCity,
						regionDistrictId: response.data.regionDistrict
					}
        const addressName = getRegionNameById(this.addressOptions,address);
        const data = {
          ...response.data,
          companyId: response.data.companyId.toString(),
          industry: industry,
          time: response.data.beginTime ? [response.data.beginTime, response.data.endTime] : null,
          age: `${response.data.limitAgeMin}-${response.data.limitAgeMax}`,
          salary: `${response.data.salaryMin}-${response.data.salaryMax}`,
          addressName: addressName,
        };
        this.drawer = true;
        this.details = data;
      });
    },

    // 薪资范围
    validateSalaryRange(rule, value, callback) {
      const regex = /^\d{1,}-\d{1,}$/;
      if (!value) {
        return callback(new Error("请输入薪资范围"));
      }
      if (!regex.test(value)) {
        return callback(
          new Error("薪资范围格式不正确，应为数字-数字，例如100-200")
        );
      }
      const [min, max] = value.split("-").map(Number);
      if (min >= max) {
        return callback(new Error("最小值应小于最大值"));
      }
      callback();
    },

    /** 查询零工岗位列表 */
    getList() {
      this.loading = true;
      listInfo(this.addDateRange(this.queryParams, this.dateRange)).then(
        (response) => {
          this.infoList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        companyId: null,
        companyName: null,
        companyAddress: null,
        mapLongitude: null,
        mapLatitude: null,
        gigCode: null,
        gigCodeArr: null,
        jobRequirement: null,
        salaryMin: null,
        salaryMax: null,
        negotiable: null,
        needCount: null,
        unLimitCount: null,
        applyCount: null,
        settlementMethodCode: null,
        beginTime: null,
        endTime: null,
        status: null,
        approved: 1,
        approvedTime: null,
        approvedBy: null,
        unApprovedTime: null,
        unApprovedBy: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        delFlag: null,
        limitAgeMin: null,
        limitAgeMax: null,
        limitAge: null,
        salary: null,
        time: [],
      };
      this.resetForm("form");
      // this.resetFields("form");
      // this.form = Object.assign({}, this.$options.data().form);
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      (this.dateRange = []),
        (this.queryParams.params.salary = null),
        (this.queryParams.params.limitAge = null),
        (this.queryParams.approved = null),
        this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加零工岗位";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      console.log("修改按钮操作", row);
      getInfo(id).then((response) => {
        console.log("response.data", this.workOptions, response.data);
        const industry = this.findParentValue(
          this.workOptions,
          response.data.gigCode
        );
        if(industry){
          this.workChange(industry);
        }
        const data = {
          ...response.data,
          companyId: response.data.companyId.toString(),
          industry: industry,
          time: response.data.beginTime ? [response.data.beginTime, response.data.endTime] : null,
          age: `${response.data.limitAgeMin}-${response.data.limitAgeMax}`,
          salary: `${response.data.salaryMin}-${response.data.salaryMax}`,
        };
        console.log("data", data);
        (this.time = [response.data.beginTime, response.data.endTime]),
          (this.form = data);
        this.open = true;
        this.title = "修改零工岗位";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          console.log("this.form", this.form);
          const data = {
            ...this.form,
            beginTime: this.form.time[0],
            endTime: this.form.time[1],
            salaryMin: this.form.salary.split("-")[0],
            salaryMax: this.form.salary.split("-")[1],
            limitAgeMin: this.form.age.split("-")[0],
            limitAgeMax: this.form.age.split("-")[1],
          };
          delete data.salary;
          console.log("data", data);
          if (this.form.id != null) {
            updateInfo(data).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addInfo(data).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除零工岗位编号为"' + ids + '"的数据项？')
        .then(function () {
          return delInfo(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "jobs/info/export",
        {
          ...this.queryParams,
        },
        `info_${new Date().getTime()}.xlsx`
      );
    },
    // 审核
    handleCommand(command, row) {
      console.log("审核", command, row);
      switch (command) {
        case "pass":
          this.approve(row);
          break;
        case "reject":
          this.reject(row);
          break;
        case "reset":
          this.resets(row);
          break;
        default:
          break;
      }
    },

    approve(row) {
      checkApproved(row.id)
        .then((response) => {
          this.getList();
          this.$modal.msgSuccess("操作成功");
        })
        .catch(() => { });
    },
    reject(row) {
      checkDisApproved(row.id)
        .then((response) => {
          this.getList();
          this.$modal.msgSuccess("操作成功");
        })
        .catch(() => { });
    },
    resets(row) {
      checkUnApproved(row.id)
        .then((response) => {
          this.getList();
          this.$modal.msgSuccess("操作成功");
        })
        .catch(() => { });
    },

    // 获取公司/用户 下拉框
    getUserOptions() {
      userOptions().then((response) => {
        this.userOptions = response.data;
      });
    },

    // 获取公司id 对应的label
    getCompanyLabel(companyId) {
      const option = this.userOptions.find(
        (item) => item.value === companyId?.toString()
      );
      return option ? option.label : "";
    },

    // 获取岗位级联数据
    getTypeCascadeOptions() {
      typeCascadeList().then((response) => {
        this.workOptions = response.data;
      });
    },

    // 行业
    workChange(value) {
      this.form.gigCode = "";
      this.form.gigCodeArr = [];
      const data = this.workOptions.find(
        (item) => item.value === value
      ).children;
      this.workTypeOptions = data;
      console.log("行业--data", data);
    },

    // 获取薪资范围
    getSalaryRange(row) {
      const salaryMin = row.salaryMin ?? null;
      const salaryMax = row.salaryMax ?? null;

      if (typeof salaryMin !== "number" || typeof salaryMax !== "number") {
        return "";
      }

      if (salaryMin === null && salaryMax === null) {
        return "";
      }

      if (salaryMin === null) {
        return `0~${salaryMax}`;
      }

      if (salaryMax === null) {
        return `${salaryMin}~0`;
      }

      return `${salaryMin}~${salaryMax}`;
    },

    findParentValue(data, targetValue) {
      // 遍历每一项
      for (let item of data) {
        if (item.children) {
          // 遍历子项
          for (let child of item.children) {
            if (child.value === targetValue) {
              return item.value; // 返回父级的 value
            }
          }
        }
      }
      return null; // 如果没有找到，返回 null
    },
  },
};
</script>

<style>
/* 全局样式 */
.pagination-container {
  background-color: transparent !important;
}

.job-requirement {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
</style>
